package ldh.im.fxbase.component;

import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import ldh.im.fxbase.util.FileUtil;
import ldh.im.util.UploadFileUtil;

import java.io.File;

public class AudioCell extends GridPane {

    private File file;
    private int time;

    public AudioCell(File file, int time) {
        this.file = file;
        this.time = time;

        this.getStyleClass().add("file-cell");
        initUi();
    }

    private void initUi() {
        if(file == null) return;
        Label fileIconLabel = new Label();
        fileIconLabel.getStyleClass().add("file-icon");
        fileIconLabel.setGraphic(FileUtil.getFileIcon(UploadFileUtil.suffix(file.getName())));

        // 文件大小
        Label fileTimeLabel = new Label((time/1000.0) + "s");
        fileTimeLabel.getStyleClass().add("file-time");

        this.getChildren().addAll(fileIconLabel, fileTimeLabel);
        GridPane.setConstraints(fileIconLabel, 0, 0, 1, 1);
        GridPane.setConstraints(fileTimeLabel, 1, 0, 1, 1);
    }
}
